﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace S7
{
	/// <summary>
	/// Interaction logic for ShowPendingOrders.xaml
	/// </summary>
	public partial class ShowPendingOrders : Window
	{
		public ShowPendingOrders()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Thread thr = new Thread(new ThreadStart(() =>
            {
                try
                {
                    List<Order> lstFeeds = Order.Pending();
                    lbOrders.Dispatcher.Invoke(new ThreadStart(() =>
                    {
                        try
                        {
                            lbOrders.ItemsSource = lstFeeds;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                        }
                    }), null);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
            }));
            thr.IsBackground = true;
            thr.Start();
        }
	}
}